#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

#include "cmdrvfile.h"
#include "armsdkerr.h"


#define KEY0VALUE 0XF0
#define INVAKEY 0X00

static INT4 fd = 0;

/*
 * @description : main主程序
 * @param - argc : argv数组元素个数
 * @param - argv : 具体参数
 * @return : 0 成功;其他 失败
 */
INT4 enableKey()
{
    INT4 i4Ret;
    UINT1 keyvalue;

    fd = fileOpen("/dev/key");
    /* 打开驱动 */
    while(1)
    {
        read(fd, &keyvalue, sizeof(keyvalue));
        if (keyvalue == KEY0VALUE)
        {
            printf("Key 2 press, value = %#x\r\n", keyvalue);
        }
    }

    i4Ret = close(fd); /* 关闭文件 */

    if(i4Ret < 0)
    {
        printf("file %s close failed!\r\n", "/dev/key");
        return -1;
    }

    return 0;
}

INT4 disableKey()
{
    INT4 i4Ret;

    i4Ret = close(fd);
    if (i4Ret != SUCCESS)
    {
        printf("keys close failed!\r\n");
        return FAILURE;
    }

    return SUCCESS;
}


